from ..models import Strategy, StrategyGlobalAction, CreditGlobalAction, SafetyCreditEvaluation

LEVEL_LOW = Strategy.STRATEGY_LEVELS[0][0]
LEVEL_MEDIUM = Strategy.STRATEGY_LEVELS[1][0]
LEVEL_HIGH = Strategy.STRATEGY_LEVELS[2][0]

CHANNEL_ALL = Strategy.STRATEGY_CHANNELS[0][0]  # 不分渠道
CHANNEL_APP = Strategy.STRATEGY_CHANNELS[1][0]  # Android
CHANNEL_PC = Strategy.STRATEGY_CHANNELS[2][0]  # Windows
CHANNEL_WEB = Strategy.STRATEGY_CHANNELS[3][0]  # Web
CHANNEL_LINUX = Strategy.STRATEGY_CHANNELS[4][0]  # Linux

CATEGORY_AUTH = ('身份认证', 'STG/AUTH')
CATEGORY_TERMINAL = ('终端威胁', 'STG/TERM')  # 终端安全 改为 终端威胁
CATEGORY_MAIL = ('邮件安全', 'STG/MAIL')
CATEGORY_SHARE = ('文件共享', 'STG/SHR')
CATEGORY_DOWNLOAD = ('文件下载', 'STG/DL')
CATEGORY_RESOURCE = ('资源请求', 'STG/RES')
CATEGORY_ENV = ('安全基线', 'STG/ENV')
CATEGORY_BASEAUTH = ('认证策略', 'STG/BASE')
CATEGORY_BASECONFIG = ('基础配置', 'STG/CONF')  # 基础配置
CATEGORY_REALTIMEPROTECT = ('实时防护', 'STG/REALTIMEPRO')
CATEGORY_PERIPHERAL = ('外设管控', 'STG/PERIPHERAL')
CATEGORY_HOSTAUDIT = ('安全审计', 'STG/HOSTAUDIT')
CATEGORY_DEVICE = ('设备登录', 'STG/DEVICE')

strategy_dict = {
    "身份认证": {
        "设备登录异常二次认证": [(f'{CATEGORY_AUTH[1]}-20', CHANNEL_PC), (f'{CATEGORY_AUTH[1]}-21', CHANNEL_APP)],
        "异地登录二次认证": [(f'{CATEGORY_AUTH[1]}-19', CHANNEL_PC), (f'{CATEGORY_AUTH[1]}-31', CHANNEL_APP)],
        "二次认证冻结": [(f'{CATEGORY_AUTH[1]}-16', CHANNEL_WEB), (f'{CATEGORY_AUTH[1]}-17', CHANNEL_PC),
                     (f'{CATEGORY_AUTH[1]}-18', CHANNEL_APP)],
        "认证失败冻结": [(f'{CATEGORY_AUTH[1]}-13', CHANNEL_WEB), (f'{CATEGORY_AUTH[1]}-14', CHANNEL_PC),
                   (f'{CATEGORY_AUTH[1]}-15', CHANNEL_APP)],
        "短信验证失败冻结": [(f'{CATEGORY_AUTH[1]}-10', CHANNEL_WEB), (f'{CATEGORY_AUTH[1]}-11', CHANNEL_PC),
                     (f'{CATEGORY_AUTH[1]}-12', CHANNEL_APP)],
        "单次认证失效": [(f'{CATEGORY_AUTH[1]}-2', CHANNEL_WEB), (f'{CATEGORY_AUTH[1]}-23', CHANNEL_PC),
                   (f'{CATEGORY_AUTH[1]}-24', CHANNEL_APP)],
        "闲时登出": [(f'{CATEGORY_AUTH[1]}-3', CHANNEL_WEB), (f'{CATEGORY_AUTH[1]}-25', CHANNEL_PC),
                 (f'{CATEGORY_AUTH[1]}-26', CHANNEL_APP)],
        "异常时间登录": [(f'{CATEGORY_AUTH[1]}-5', CHANNEL_WEB), (f'{CATEGORY_AUTH[1]}-27', CHANNEL_PC),
                   (f'{CATEGORY_AUTH[1]}-28', CHANNEL_APP)],
        # "新设备认证": [(f'{CATEGORY_AUTH[1]}-29', CHANNEL_PC), (f'{CATEGORY_AUTH[1]}-9', CHANNEL_APP)],
        "其他用户登录": [(f'{CATEGORY_AUTH[1]}-7', CHANNEL_PC), (f'{CATEGORY_AUTH[1]}-22', CHANNEL_APP)],
        "单设备登录": [(f'{CATEGORY_AUTH[1]}-8', CHANNEL_PC), (f'{CATEGORY_AUTH[1]}-30', CHANNEL_APP)]
    },
    "终端威胁": {
        "终端检出恶意apk": [(f'{CATEGORY_TERMINAL[1]}-2', CHANNEL_APP)],
        "终端检出风险apk": [(f'{CATEGORY_TERMINAL[1]}-3', CHANNEL_APP)],
        "终端检出敏感apk": [(f'{CATEGORY_TERMINAL[1]}-4', CHANNEL_APP)],
        "检出短信钓鱼URL": [(f'{CATEGORY_TERMINAL[1]}-5', CHANNEL_APP)],
        "检出访问钓鱼URL": [(f'{CATEGORY_TERMINAL[1]}-6', CHANNEL_APP)],
        "检出访问恶意WiFi": [(f'{CATEGORY_TERMINAL[1]}-7', CHANNEL_APP)],
    },
    "邮件安全": {
        "邮件附件大小": [(f'{CATEGORY_MAIL[1]}-1', CHANNEL_ALL)],
        "密级邮件附件": [(f'{CATEGORY_MAIL[1]}-2', CHANNEL_ALL)],
        "邮件附件敏感字": [(f'{CATEGORY_MAIL[1]}-3', CHANNEL_ALL)],
    },
    "文件共享": {
        "密级文件共享": [(f'{CATEGORY_SHARE[1]}-1', CHANNEL_ALL)],
        "共享文件涉敏": [(f'{CATEGORY_SHARE[1]}-2', CHANNEL_ALL)],
    },
    "文件下载": {
        "密级文件下载": [(f'{CATEGORY_DOWNLOAD[1]}-1', CHANNEL_ALL)],
        "下载文件涉敏": [(f'{CATEGORY_DOWNLOAD[1]}-2', CHANNEL_ALL)],
    },
    "资源请求": {
        "资源请求频次过高": [(f'{CATEGORY_RESOURCE[1]}-1', CHANNEL_ALL)],
        "资源请求越权": [(f'{CATEGORY_RESOURCE[1]}-2', CHANNEL_ALL)],
        "资源请求总量过高": [(f'{CATEGORY_RESOURCE[1]}-3', CHANNEL_ALL)],
        "当日资源请求异常": [(f'{CATEGORY_RESOURCE[1]}-4', CHANNEL_ALL)],
    },
    "基准环境": {
        "设备需运行在安全域（异常设备登录）": [(f'{CATEGORY_ENV[1]}-6', CHANNEL_PC)],
        "禁止运行虚拟机软件": [(f'{CATEGORY_ENV[1]}-7', CHANNEL_PC)],
        "禁止运行录屏软件": [(f'{CATEGORY_ENV[1]}-9', CHANNEL_PC)],
        "禁止运行远控软件": [(f'{CATEGORY_ENV[1]}-11', CHANNEL_PC)],
        "杀毒软件需调起运行": [(f'{CATEGORY_ENV[1]}-13', CHANNEL_PC)],
        "防火墙需调起运行": [(f'{CATEGORY_ENV[1]}-15', CHANNEL_PC)],
    },
    "认证策略": {}
}

strategy_list = [
    # 单次认证失效策略
    Strategy(
        name='单次认证失效',
        description='单次认证有效时长{trigger_period}小时，超时'
                    '<span style="color:red">重新登录</span>',
        level=LEVEL_LOW,
        channel=CHANNEL_WEB,
        weight=3,
        category=CATEGORY_AUTH[0],
        uid=f'{CATEGORY_AUTH[1]}-2',
        trigger_period=20
    ),
    Strategy(
        name='单次认证失效',
        description='单次认证有效时长{trigger_period}小时，超时'
                    '<span style="color:red">重新登录</span>',
        level=LEVEL_LOW,
        channel=CHANNEL_PC,
        weight=3,
        category=CATEGORY_AUTH[0],
        uid=f'{CATEGORY_AUTH[1]}-23',
        trigger_period=20
    ),
    Strategy(
        name='单次认证失效',
        description='单次认证有效时长{trigger_period}小时，超时'
                    '<span style="color:red">重新登录</span>',
        level=LEVEL_LOW,
        channel=CHANNEL_APP,
        weight=3,
        category=CATEGORY_AUTH[0],
        uid=f'{CATEGORY_AUTH[1]}-24',
        trigger_period=20
    ),
    Strategy(
        name='单次认证失效',
        description='单次认证有效时长{trigger_period}小时，超时'
                    '<span style="color:red">重新登录</span>',
        level=LEVEL_LOW,
        channel=CHANNEL_LINUX,
        weight=3,
        category=CATEGORY_AUTH[0],
        uid=f'{CATEGORY_AUTH[1]}-34',
        trigger_period=20
    ),
    # 闲时登出策略
    Strategy(
        name='闲时登出',
        description='长时间未操作，闲时登出时长{trigger_period}分钟，'
                    '<span style="color:red">重新登录</span>',
        level=LEVEL_LOW,
        channel=CHANNEL_WEB,
        weight=3,
        category=CATEGORY_AUTH[0],
        trigger_period=120,
        uid=f'{CATEGORY_AUTH[1]}-3'
    ),
    Strategy(
        name='闲时登出',
        description='长时间未操作，闲时登出时长{trigger_period}分钟，'
                    '<span style="color:red">重新登录</span>',
        level=LEVEL_LOW,
        channel=CHANNEL_PC,
        weight=3,
        category=CATEGORY_AUTH[0],
        trigger_period=120,
        uid=f'{CATEGORY_AUTH[1]}-25'
    ),
    Strategy(
        name='闲时登出',
        description='长时间未操作，闲时登出时长{trigger_period}分钟，'
                    '<span style="color:red">重新登录</span>',
        level=LEVEL_LOW,
        channel=CHANNEL_APP,
        weight=3,
        category=CATEGORY_AUTH[0],
        trigger_period=120,
        uid=f'{CATEGORY_AUTH[1]}-26'
    ),
    Strategy(
        name='闲时登出',
        description='长时间未操作，闲时登出时长{trigger_period}分钟，'
                    '<span style="color:red">重新登录</span>',
        level=LEVEL_LOW,
        channel=CHANNEL_LINUX,
        weight=3,
        category=CATEGORY_AUTH[0],
        trigger_period=120,
        uid=f'{CATEGORY_AUTH[1]}-35'
    ),

    # 异常时间登录策略
    Strategy(
        name='异常时间登录',
        description='在{start_time}~{end_time}登录的均为异常时间登录，做出{action}处理。',
        start_time='01:00',
        end_time='05:00',
        action=3,  # (3, "短信二次认证"), (6, '本次禁止登录'),
        level=LEVEL_MEDIUM,
        channel=CHANNEL_WEB,
        weight=5,
        category=CATEGORY_AUTH[0],
        uid=f'{CATEGORY_AUTH[1]}-5'
    ),
    Strategy(
        name='异常时间登录',
        description='在{start_time}~{end_time}登录的均为异常时间登录，做出{action}处理。',
        start_time='01:00',
        end_time='05:00',
        action=3,  # (3, "短信二次认证"), (6, '本次禁止登录'),
        level=LEVEL_MEDIUM,
        channel=CHANNEL_PC,
        weight=5,
        category=CATEGORY_AUTH[0],
        uid=f'{CATEGORY_AUTH[1]}-27'
    ),
    Strategy(
        name='异常时间登录',
        description='在{start_time}~{end_time}登录的均为异常时间登录，做出{action}处理。',
        start_time='01:00',
        end_time='05:00',
        action=3,  # (3, "短信二次认证"), (6, '本次禁止登录'),
        level=LEVEL_MEDIUM,
        channel=CHANNEL_APP,
        weight=5,
        category=CATEGORY_AUTH[0],
        uid=f'{CATEGORY_AUTH[1]}-28'
    ),
    Strategy(
        name='异常时间登录',
        description='在{start_time}~{end_time}登录的均为异常时间登录，做出{action}处理。',
        start_time='01:00',
        end_time='05:00',
        action=3,  # (3, "短信二次认证"), (6, '本次禁止登录'),
        level=LEVEL_MEDIUM,
        channel=CHANNEL_LINUX,
        weight=5,
        category=CATEGORY_AUTH[0],
        uid=f'{CATEGORY_AUTH[1]}-36'
    ),
    # 检出恶意apk处置
    Strategy(
        name='检出恶意APK处置',
        description='扫描检出移动端有恶意apk时，做出{action}处理。',
        action=7,  # (7, '提示用户')(6, "本次禁止登录"),
        level=LEVEL_HIGH,
        channel=CHANNEL_APP,
        weight=7,
        category=CATEGORY_TERMINAL[0],
        uid=f'{CATEGORY_TERMINAL[1]}-2'
    ),
    # 检出风险APK处置
    Strategy(
        name='检出风险APK处置',
        description='扫描检出移动端有风险apk时，做出{action}处理。',
        action=8,  # (8, '生成并记录风险日志'), (6, "本次禁止登录"),
        level=LEVEL_MEDIUM,
        channel=CHANNEL_APP,
        weight=5,
        category=CATEGORY_TERMINAL[0],
        uid=f'{CATEGORY_TERMINAL[1]}-3'
    ),
    # 检出敏感APK处置
    Strategy(
        name='检出敏感APK处置',
        description='扫描检出移动端有敏感apk时，做出{action}处理。',
        action=8,  # (8, '生成并记录风险日志'), (6, "本次禁止登录"),
        level=LEVEL_MEDIUM,
        channel=CHANNEL_APP,
        weight=5,
        category=CATEGORY_TERMINAL[0],
        uid=f'{CATEGORY_TERMINAL[1]}-4'
    ),
    # # 检出钓鱼URL处置
    # Strategy(
    #     name='检出钓鱼URL处置',
    #     description='扫描检出移动端短信或邮箱中有钓鱼URL，做出{action}处理。',
    #     action=7,   # (7, '提示用户'), (6, "本次禁止登录"),
    #     level=LEVEL_MEDIUM,
    #     channel=CHANNEL_APP,
    #     weight=5,
    #     category=CATEGORY_TERMINAL[0],
    #     uid=f'{CATEGORY_TERMINAL[1]}-5'
    # ),
    # # 检出访问钓鱼URL处置
    # Strategy(
    #     name='检出访问钓鱼URL处置',
    #     description='扫描检出移动端连接恶意URL，做出{action}处理。',
    #     action=7,  # (7, '提示用户'), (6, "本次禁止登录"),
    #     level=LEVEL_HIGH,
    #     channel=CHANNEL_APP,
    #     weight=10,
    #     category=CATEGORY_TERMINAL[0],
    #     uid=f'{CATEGORY_TERMINAL[1]}-6'
    # ),
    # # 检出访问恶意WiFi处置
    # Strategy(
    #     name='检出访问恶意WiFi处置',
    #     description='扫描检出移动端连接恶意WiFi，做出{action}处理。',
    #     action=7,  # (7, '提示用户'), (6, "本次禁止登录"),
    #     level=LEVEL_HIGH,
    #     channel=CHANNEL_APP,
    #     weight=10,
    #     category=CATEGORY_TERMINAL[0],
    #     uid=f'{CATEGORY_TERMINAL[1]}-7'
    # ),
    # 邮件附件大小策略
    Strategy(
        name='邮件附件大小',
        description='邮件附件最大为<span style="color:red">200M</span>，'
                    '<span style="color:red">超出该大小邮件发送失败</span>。',
        level=LEVEL_LOW,
        weight=3,
        category=CATEGORY_MAIL[0],
        uid=f'{CATEGORY_MAIL[1]}-1'
    ),
    # 密级邮件附件
    Strategy(
        name='密级邮件附件',
        description='匹配密级文件的<span style="color:red">MD5</span>，'
                    '一旦匹配到该MD5<span style="color:red">拦截该邮件发送</span>。',
        level=LEVEL_HIGH,
        weight=10,
        category=CATEGORY_MAIL[0],
        uid=f'{CATEGORY_MAIL[1]}-2'
    ),
    # 邮件附件敏感字策略
    Strategy(
        name='邮件附件敏感字',
        description='匹配到密级文件中有<span style="color:red">敏感字</span>，'
                    '预警提示防止泄露。',
        level=LEVEL_LOW,
        weight=3,
        category=CATEGORY_MAIL[0],
        uid=f'{CATEGORY_MAIL[1]}-3'
    ),
    # 密级文件共享策略
    Strategy(
        name='密级文件共享',
        description='匹配密级文件的<span style="color:red">MD5</span>，'
                    '一旦匹配到该MD5<span style="color:red">禁止该文件共享</span>。',
        level=LEVEL_HIGH,
        weight=10,
        category=CATEGORY_SHARE[0],
        uid=f'{CATEGORY_SHARE[1]}-1'
    ),
    # 共享文件涉敏策略
    Strategy(
        name='共享文件涉敏',
        description='匹配到密级文件中有<span style="color:red">敏感字</span>，'
                    '<span style="color:red">提示给管理员</span>，防止泄露。',
        level=LEVEL_LOW,
        weight=3,
        category=CATEGORY_SHARE[0],
        uid=f'{CATEGORY_SHARE[1]}-2'
    ),
    # 密级文件下载策略
    Strategy(
        name='密级文件下载',
        description='匹配密级文件的<span style="color:red">MD5</span>，'
                    '一旦匹配到该MD5<span style="color:red">禁止该文件下载</span>。',
        level=LEVEL_HIGH,
        weight=7,
        category=CATEGORY_DOWNLOAD[0],
        uid=f'{CATEGORY_DOWNLOAD[1]}-1'
    ),
    # 下载文件涉敏策略
    Strategy(
        name='下载文件涉敏',
        description='匹配到密级文件中有<span style="color:red">敏感字</span>，'
                    '<span style="color:red">提示给管理员</span>，防止泄露。',
        level=LEVEL_LOW,
        weight=3,
        category=CATEGORY_DOWNLOAD[0],
        uid=f'{CATEGORY_DOWNLOAD[1]}-2'
    ),
    # 资源请求频次过高策略
    Strategy(
        name='资源请求频次过高',
        description='资源请求频次达到{num_value}次/秒，'
                    '<span style="color:red">注销该用户登录状态</span>（强制退出），要求该用户登录。',
        level=LEVEL_HIGH,
        weight=7,
        channel=CHANNEL_APP,
        category=CATEGORY_RESOURCE[0],
        num_value=100,
        action=6,
        uid=f'{CATEGORY_RESOURCE[1]}-1'
    ),
    Strategy(
        name='资源请求频次过高',
        description='资源请求频次达到{num_value}次/秒，'
                    '<span style="color:red">注销该用户登录状态</span>（强制退出），要求该用户登录。',
        level=LEVEL_HIGH,
        weight=7,
        channel=CHANNEL_PC,
        category=CATEGORY_RESOURCE[0],
        num_value=100,
        action=6,
        uid=f'{CATEGORY_RESOURCE[1]}-5'
    ),
    Strategy(
        name='资源请求频次过高',
        description='资源请求频次达到{num_value}次/秒，'
                    '<span style="color:red">注销该用户登录状态</span>（强制退出），要求该用户登录。',
        level=LEVEL_HIGH,
        weight=7,
        channel=CHANNEL_WEB,
        category=CATEGORY_RESOURCE[0],
        num_value=100,
        action=6,
        uid=f'{CATEGORY_RESOURCE[1]}-6'
    ),
    Strategy(
        name='资源请求频次过高',
        description='资源请求频次达到{num_value}次/秒，'
                    '<span style="color:red">注销该用户登录状态</span>（强制退出），要求该用户登录。',
        level=LEVEL_HIGH,
        weight=7,
        channel=CHANNEL_LINUX,
        category=CATEGORY_RESOURCE[0],
        num_value=100,
        action=6,
        uid=f'{CATEGORY_RESOURCE[1]}-7'
    ),
    # 资源请求越权策略
    Strategy(
        name='资源请求越权',
        description='资源请求越权，禁止用户访问该资源，跳转到默认访问页，记录风险日志。如策略关闭，风险日志将不会记录。',
        level=LEVEL_MEDIUM,
        weight=5,
        channel=CHANNEL_APP,
        category=CATEGORY_RESOURCE[0],
        uid=f'{CATEGORY_RESOURCE[1]}-2'
    ),
    Strategy(
        name='资源请求越权',
        description='资源请求越权，禁止用户访问该资源，跳转到默认访问页，记录风险日志。如策略关闭，风险日志将不会记录。',
        level=LEVEL_MEDIUM,
        weight=5,
        channel=CHANNEL_PC,
        category=CATEGORY_RESOURCE[0],
        uid=f'{CATEGORY_RESOURCE[1]}-8'
    ),
    Strategy(
        name='资源请求越权',
        description='资源请求越权，禁止用户访问该资源，跳转到默认访问页，记录风险日志。如策略关闭，风险日志将不会记录。',
        level=LEVEL_MEDIUM,
        weight=5,
        channel=CHANNEL_WEB,
        category=CATEGORY_RESOURCE[0],
        uid=f'{CATEGORY_RESOURCE[1]}-9'
    ),
    Strategy(
        name='资源请求越权',
        description='资源请求越权，禁止用户访问该资源，跳转到默认访问页，记录风险日志。如策略关闭，风险日志将不会记录。',
        level=LEVEL_MEDIUM,
        weight=5,
        channel=CHANNEL_LINUX,
        category=CATEGORY_RESOURCE[0],
        uid=f'{CATEGORY_RESOURCE[1]}-10'
    ),
    # 资源请求总量过高策略
    Strategy(
        name='资源请求总量过高',
        description='资源请求总量达到{action_times}次/时，'
                    '<span style="color:red">告知管理员预警提示</span>，并对该用户冻结{num_value}分钟处理',
        level=LEVEL_HIGH,
        weight=7,
        channel=CHANNEL_APP,
        category=CATEGORY_RESOURCE[0],
        action_times=100000,
        num_value=120,
        action=1,
        uid=f'{CATEGORY_RESOURCE[1]}-3'
    ),
    Strategy(
        name='资源请求总量过高',
        description='资源请求总量达到{action_times}次/时，'
                    '<span style="color:red">告知管理员预警提示</span>，并对该用户冻结{num_value}分钟处理',
        level=LEVEL_HIGH,
        weight=7,
        channel=CHANNEL_PC,
        category=CATEGORY_RESOURCE[0],
        action_times=100000,
        num_value=120,
        action=1,
        uid=f'{CATEGORY_RESOURCE[1]}-11'
    ),
    Strategy(
        name='资源请求总量过高',
        description='资源请求总量达到{action_times}次/时，'
                    '<span style="color:red">告知管理员预警提示</span>，并对该用户冻结{num_value}分钟处理',
        level=LEVEL_HIGH,
        weight=7,
        channel=CHANNEL_WEB,
        category=CATEGORY_RESOURCE[0],
        action_times=100000,
        num_value=120,
        action=1,
        uid=f'{CATEGORY_RESOURCE[1]}-12'
    ),
    Strategy(
        name='资源请求总量过高',
        description='资源请求总量达到{action_times}次/时，'
                    '<span style="color:red">告知管理员预警提示</span>，并对该用户冻结{num_value}分钟处理',
        level=LEVEL_HIGH,
        weight=7,
        channel=CHANNEL_LINUX,
        category=CATEGORY_RESOURCE[0],
        action_times=100000,
        num_value=120,
        action=1,
        uid=f'{CATEGORY_RESOURCE[1]}-13'
    ),
    # # 当日资源请求异常策略
    # Strategy(
    #     name='当日资源请求异常',
    #     description='该用户本日资源请求频率超过同期正常范围，'
    #                 '对该用户冻结{num_value}分钟处理。',
    #     level=LEVEL_HIGH,
    #     weight=7,
    #     channel=CHANNEL_APP,
    #     category=CATEGORY_RESOURCE[0],
    #     num_value=120,
    #     action=1,
    #     uid=f'{CATEGORY_RESOURCE[1]}-4'
    # ),
    # Strategy(
    #     name='当日资源请求异常',
    #     description='该用户本日资源请求频率超过同期正常范围，'
    #                 '对该用户冻结{num_value}分钟处理。',
    #     level=LEVEL_HIGH,
    #     weight=7,
    #     channel=CHANNEL_PC,
    #     category=CATEGORY_RESOURCE[0],
    #     num_value=120,
    #     action=1,
    #     uid=f'{CATEGORY_RESOURCE[1]}-14'
    # ),
    # Strategy(
    #     name='当日资源请求异常',
    #     description='该用户本日资源请求频率超过同期正常范围，'
    #                 '对该用户冻结{num_value}分钟处理。',
    #     level=LEVEL_HIGH,
    #     weight=7,
    #     channel=CHANNEL_WEB,
    #     category=CATEGORY_RESOURCE[0],
    #     num_value=120,
    #     action=1,
    #     uid=f'{CATEGORY_RESOURCE[1]}-15'
    # ),
    # Strategy(
    #     name='当日资源请求异常',
    #     description='该用户本日资源请求频率超过同期正常范围，'
    #                 '对该用户冻结{num_value}分钟处理。',
    #     level=LEVEL_HIGH,
    #     weight=7,
    #     channel=CHANNEL_LINUX,
    #     category=CATEGORY_RESOURCE[0],
    #     num_value=120,
    #     action=1,
    #     uid=f'{CATEGORY_RESOURCE[1]}-16'
    # ),
    # 设备需运行在安全域（异常设备登录）
    Strategy(
        name='设备需运行在安全域（异常设备登录）',
        description="检测到设备未运行在安全域",
        level=LEVEL_LOW,
        channel=CHANNEL_PC,
        weight=3,
        category=CATEGORY_ENV[0],
        uid=f'{CATEGORY_ENV[1]}-6'
    ),
    # 用户登录认证策略
    Strategy(
        name='二次认证冻结',
        description="用户连续<span>{trigger_period}分钟内短信验证码提交失败达{trigger_times}</span>次，"
                    "对该用户冻结{action_period}分钟后恢复正常状态。",
        level=LEVEL_MEDIUM,
        channel=CHANNEL_WEB,
        weight=5,
        category=CATEGORY_AUTH[0],
        uid=f'{CATEGORY_AUTH[1]}-16',  # 新需求调整
        trigger_period=10,
        trigger_times=5,
        action_period=15,
        action=1,
    ),
    # 用户登录认证策略
    Strategy(
        name='认证失败冻结',
        description="用户连续{trigger_period}分钟内无效登录{trigger_times}次，对该用户冻结{action_period}分钟后恢复正常状态。",
        level=LEVEL_HIGH,
        channel=CHANNEL_WEB,
        weight=7,
        category=CATEGORY_AUTH[0],
        uid=f'{CATEGORY_AUTH[1]}-13',  # 新需求调整
        action=1,
        trigger_period=10,
        trigger_times=5,
        action_period=15
    ),
    # 用户登录认证策略
    Strategy(
        name='短信验证失败冻结',
        description="用户连续{trigger_period}分钟内短信验证码提交失败达{trigger_times}次后对该用户冻结{action_period}分钟处理",
        level=LEVEL_HIGH,
        channel=CHANNEL_WEB,
        weight=7,
        category=CATEGORY_AUTH[0],
        uid=f'{CATEGORY_AUTH[1]}-10',  # 新需求调整
        trigger_period=10,
        trigger_times=5,
        action=1,
        action_period=15
    ),
    # 二次认证冻结
    Strategy(
        name='二次认证冻结',
        description="用户连续<span>{trigger_period}分钟内短信验证码提交失败达{trigger_times}</span>次，"
                    "对该用户冻结{action_period}分钟后恢复正常状态。",
        level=LEVEL_MEDIUM,
        channel=CHANNEL_PC,
        weight=5,
        category=CATEGORY_AUTH[0],
        uid=f'{CATEGORY_AUTH[1]}-17',  # 新需求调整
        trigger_period=10,
        trigger_times=5,
        action_period=15,
        action=1,
    ),
    Strategy(
        name='二次认证冻结',
        description="用户连续<span>{trigger_period}分钟内短信验证码提交失败达{trigger_times}</span>次，"
                    "对该用户冻结{action_period}分钟后恢复正常状态。",
        level=LEVEL_MEDIUM,
        channel=CHANNEL_APP,
        weight=5,
        category=CATEGORY_AUTH[0],
        uid=f'{CATEGORY_AUTH[1]}-18',  # 新需求调整
        trigger_period=10,
        trigger_times=5,
        action_period=15,
        action=1,
    ),
    # 认证失败冻结
    Strategy(
        name='认证失败冻结',
        description="用户连续{trigger_period}分钟内无效登录{trigger_times}次，对该用户冻结{action_period}分钟后恢复正常状态。",
        level=LEVEL_HIGH,
        channel=CHANNEL_PC,
        weight=7,
        category=CATEGORY_AUTH[0],
        uid=f'{CATEGORY_AUTH[1]}-14',  # 新需求调整
        action=1,
        trigger_period=10,
        trigger_times=5,
        action_period=15
    ),
    Strategy(
        name='认证失败冻结',
        description="用户连续{trigger_period}分钟内无效登录{trigger_times}次，对该用户冻结{action_period}分钟后恢复正常状态。",
        level=LEVEL_HIGH,
        channel=CHANNEL_APP,
        weight=7,
        category=CATEGORY_AUTH[0],
        uid=f'{CATEGORY_AUTH[1]}-15',  # 新需求调整
        action=1,
        trigger_period=10,
        trigger_times=5,
        action_period=15
    ),
    # 短信验证失败冻结
    Strategy(
        name='短信验证失败冻结',
        description="用户连续{trigger_period}分钟内短信验证码提交失败达{trigger_times}次后对该用户冻结{action_period}分钟处理",
        level=LEVEL_HIGH,
        channel=CHANNEL_PC,
        weight=7,
        category=CATEGORY_AUTH[0],
        uid=f'{CATEGORY_AUTH[1]}-11',  # 新需求调整
        trigger_period=10,
        action=1,
        trigger_times=5,
        action_period=15
    ),
    Strategy(
        name='短信验证失败冻结',
        description="用户连续{trigger_period}分钟内短信验证码提交失败达{trigger_times}次后对该用户冻结{action_period}分钟处理",
        level=LEVEL_HIGH,
        channel=CHANNEL_APP,
        weight=7,
        category=CATEGORY_AUTH[0],
        uid=f'{CATEGORY_AUTH[1]}-12',  # 新需求调整
        trigger_period=10,
        action=1,
        trigger_times=5,
        action_period=15
    ),
    # 二次认证冻结
    Strategy(
        name='二次认证冻结',
        description="用户连续<span>{trigger_period}分钟内短信验证码提交失败达{trigger_times}</span>次，"
                    "对该用户冻结{action_period}分钟后恢复正常状态。",
        level=LEVEL_MEDIUM,
        weight=5,
        channel=CHANNEL_LINUX,
        category=CATEGORY_AUTH[0],
        uid=f'{CATEGORY_AUTH[1]}-32',  # 新需求调整
        trigger_period=10,
        trigger_times=5,
        action_period=15,
        action=1,
    ),
    # 认证失败冻结
    Strategy(
        name='认证失败冻结',
        description="用户连续{trigger_period}分钟内无效登录{trigger_times}次，对该用户冻结{action_period}分钟后恢复正常状态。",
        level=LEVEL_HIGH,
        weight=7,
        channel=CHANNEL_LINUX,
        category=CATEGORY_AUTH[0],
        uid=f'{CATEGORY_AUTH[1]}-33',  # 新需求调整
        action=1,
        trigger_period=10,
        trigger_times=5,
        action_period=15
    ),

    # 禁止运行虚拟机软件
    Strategy(
        name='禁止运行虚拟机软件',
        description="检测到运行Vmware或Hyper-V虚拟机软件，限制终端登录",
        level=LEVEL_LOW,
        channel=CHANNEL_PC,
        weight=3,
        action=6,
        category=CATEGORY_ENV[0],
        uid=f'{CATEGORY_ENV[1]}-7'
    ),
    # 禁止运行录屏软件
    Strategy(
        name='禁止运行录屏软件',
        description="检测到运行Bandicam，windows自带等录屏软件，限制终端登录",
        level=LEVEL_MEDIUM,
        channel=CHANNEL_PC,
        weight=5,
        action=6,
        category=CATEGORY_ENV[0],
        uid=f'{CATEGORY_ENV[1]}-9'
    ),
    # 禁止运行远控软件
    Strategy(
        name='禁止运行远控软件',
        description="检测到运行向日葵，QQ远程控制、teamviewer等远控软件，限制终端登录",
        level=LEVEL_HIGH,
        channel=CHANNEL_PC,
        weight=7,
        action=6,
        category=CATEGORY_ENV[0],
        uid=f'{CATEGORY_ENV[1]}-11'
    ),
    # 杀毒软件需调起运行
    Strategy(
        name='杀毒软件需调起运行',
        description="检测到未运行必备装机软件(杀毒、加密等),限制终端登录",
        level=LEVEL_HIGH,
        channel=CHANNEL_PC,
        weight=7,
        action=6,
        category=CATEGORY_ENV[0],
        uid=f'{CATEGORY_ENV[1]}-13'
    ),
    # 防火墙需调起运行
    Strategy(
        name='防火墙需调起运行',
        description="检测到未运行防火墙，限制终端登录",
        level=LEVEL_HIGH,
        channel=CHANNEL_PC,
        weight=7,
        action=6,
        category=CATEGORY_ENV[0],
        uid=f'{CATEGORY_ENV[1]}-15'
    ),
    # 安全基线检测
    Strategy(
        name='安全基线检测',
        description="扫描检出终端安全基线风险，提示用户并提供安全修复建议。",
        level=LEVEL_MEDIUM,
        weight=5,
        channel=CHANNEL_LINUX,
        category=CATEGORY_ENV[0],
        uid=f'{CATEGORY_ENV[1]}-16'
    ),

    # 设备登录策略
    # 单设备登录
    Strategy(
        name='单设备登录',
        description="每个用户仅支持1台设备注册和1台设备有效登录（原登录设备下线），该策略默认开启，且建议开启。如果关闭该策略，"
                    "每个用户最多支持2台设备注册和2台设备有效登录（首台登录设备将下线）。",
        level=LEVEL_LOW,
        weight=3,
        channel=CHANNEL_PC,
        category=CATEGORY_DEVICE[0],
        uid=f'{CATEGORY_DEVICE[1]}-1'
    ),
    Strategy(
        name='单设备登录',
        description="每个用户仅支持1台设备注册和1台设备有效登录（原登录设备下线），该策略默认开启，且建议开启。如果关闭该策略，"
                    "每个用户最多支持2台设备注册和2台设备有效登录（首台登录设备将下线）。",
        level=LEVEL_LOW,
        weight=3,
        channel=CHANNEL_APP,
        category=CATEGORY_DEVICE[0],
        uid=f'{CATEGORY_DEVICE[1]}-2'
    ),
    Strategy(
        name='单设备登录',
        description="每个用户仅支持1台设备注册和1台设备有效登录（原登录设备下线），该策略默认开启，且建议开启。如果关闭该策略，"
                    "每个用户最多支持2台设备注册和2台设备有效登录（首台登录设备将下线）。",
        level=LEVEL_LOW,
        weight=3,
        channel=CHANNEL_LINUX,
        category=CATEGORY_DEVICE[0],
        uid=f'{CATEGORY_DEVICE[1]}-11'
    ),
    # 设备登录异常二次认证
    Strategy(
        name='设备登录异常二次认证',
        description="常用设备为用户已注册的设备,最近两次登录设备发生变化时,需短信验证码的安全验证",
        level=LEVEL_MEDIUM,
        channel=CHANNEL_PC,
        weight=5,
        action=3,
        category=CATEGORY_DEVICE[0],
        uid=f'{CATEGORY_DEVICE[1]}-3'
    ),
    Strategy(
        name='设备登录异常二次认证',
        description="常用设备为用户已注册的设备,最近两次登录设备发生变化时,需短信验证码的安全验证",
        level=LEVEL_MEDIUM,
        channel=CHANNEL_APP,
        weight=5,
        action=3,
        category=CATEGORY_DEVICE[0],
        uid=f'{CATEGORY_DEVICE[1]}-4'
    ),
    Strategy(
        name='设备登录异常二次认证',
        description="常用设备为用户已注册的设备,最近两次登录设备发生变化时,需短信验证码的安全认证",
        level=LEVEL_MEDIUM,
        channel=CHANNEL_LINUX,
        weight=5,
        action=3,
        category=CATEGORY_DEVICE[0],
        uid=f'{CATEGORY_DEVICE[1]}-12'
    ),
    # 用户登录异常二次认证
    Strategy(
        name='用户登录异常二次认证',
        description="设备常用用户为设备的注册用户,最近两次登录设备用户发生变化时,需短信验证码的安全认证",
        level=LEVEL_MEDIUM,
        channel=CHANNEL_PC,
        weight=5,
        action=3,
        category=CATEGORY_DEVICE[0],
        uid=f'{CATEGORY_DEVICE[1]}-5'
    ),
    Strategy(
        name='用户登录异常二次认证',
        description="设备常用用户为设备的注册用户,最近两次登录设备用户发生变化时,需短信验证码的安全认证",
        level=LEVEL_MEDIUM,
        channel=CHANNEL_APP,
        weight=5,
        action=3,
        category=CATEGORY_DEVICE[0],
        uid=f'{CATEGORY_DEVICE[1]}-6'
    ),
    # 新设备登录预警
    Strategy(
        name='新设备登录预警',
        description="该用户从未在系统中注册过的设备为新设备，用户使用任何新设备登陆认证触发预警通知。",
        level=LEVEL_LOW,
        channel=CHANNEL_PC,
        weight=3,
        category=CATEGORY_DEVICE[0],
        uid=f'{CATEGORY_DEVICE[1]}-7'
    ),
    Strategy(
        name='新设备登录预警',
        description="该用户从未在系统中注册过的设备为新设备，用户使用任何新设备登陆认证触发预警通知。",
        level=LEVEL_LOW,
        channel=CHANNEL_APP,
        weight=3,
        category=CATEGORY_DEVICE[0],
        uid=f'{CATEGORY_DEVICE[1]}-8'
    ),
    Strategy(
        name='新设备登录预警',
        description="该用户从未在系统中注册过的设备为新设备，用户使用任何新设备登陆认证触发预警通知。",
        level=LEVEL_LOW,
        channel=CHANNEL_LINUX,
        weight=3,
        category=CATEGORY_DEVICE[0],
        uid=f'{CATEGORY_DEVICE[1]}-13'
    ),
    # 异地登录二次认证
    Strategy(
        name='异地登录二次认证',
        description="常用地址为登录最多的地址,以市为单位,不在常用地址登录,需短信验证码的安全认证",
        level=LEVEL_MEDIUM,
        channel=CHANNEL_PC,
        weight=5,
        action=3,
        category=CATEGORY_DEVICE[0],
        uid=f'{CATEGORY_DEVICE[1]}-9'
    ),
    Strategy(
        name='异地登录二次认证',
        description="常用地址为登录最多的地址,以市为单位,不在常用地址登录,需短信验证码的安全认证",
        level=LEVEL_MEDIUM,
        channel=CHANNEL_APP,
        weight=5,
        action=3,
        category=CATEGORY_DEVICE[0],
        uid=f'{CATEGORY_DEVICE[1]}-10'
    ),
    Strategy(
        name='异地登录二次认证',
        description="常用地址为登录最多的地址,以市为单位,不在常用地址登录,需短信验证码的安全认证",
        level=LEVEL_MEDIUM,
        channel=CHANNEL_LINUX,
        weight=5,
        action=3,
        category=CATEGORY_DEVICE[0],
        uid=f'{CATEGORY_DEVICE[1]}-14'
    ),

    # ------------------------------------------------------------------------------------------
    # 用于演示的新增策略，基础配置
    # 文件扫描
    # Strategy(
    #     name='文件扫描',
    #     description="<span>进入压缩包扫描，扫描{trigger_times}层以内压缩包，跳过大于{num_value}MB的文件（20M-500M）</span>",
    #     trigger_times=5,
    #     num_value=200,
    #     weight=1,
    #     channel=CHANNEL_PC,
    #     category=CATEGORY_BASECONFIG[0],
    #     uid=f'{CATEGORY_BASECONFIG[1]}-1'
    # ),
    # # 病毒处理方式
    # Strategy(
    #     name='病毒处理方式',
    #     description="<span>当检测PC终端病毒后，通过{action}方式处理病毒</span>",
    #     action=0,
    #     weight=1,
    #     channel=CHANNEL_PC,
    #     category=CATEGORY_BASECONFIG[0],
    #     uid=f'{CATEGORY_BASECONFIG[1]}-2'
    # ),
    # # 病毒扫描方式
    # Strategy(
    #     name='病毒扫描方式',
    #     description="<span>采用{action}模式对PC终端进行病毒扫描</span>",
    #     action=0,
    #     weight=1,
    #     channel=CHANNEL_PC,
    #     category=CATEGORY_BASECONFIG[0],
    #     uid=f'{CATEGORY_BASECONFIG[1]}-3'
    # ),
    # # 按天定时查毒
    # Strategy(
    #     name='按天定时查毒',
    #     description="<span>在每天的{virus_time}，开启{action}扫描定时扫描任务</span>",
    #     virus_time='01:00',
    #     action=0,
    #     weight=1,
    #     channel=CHANNEL_PC,
    #     category=CATEGORY_BASECONFIG[0],
    #     uid=f'{CATEGORY_BASECONFIG[1]}-4'
    # ),
    # # 按周定时查毒
    # Strategy(
    #     name='按周定时查毒',
    #     description="<span>在每周的{virus_week_day}，开启{action}扫描定时扫描任务</span>",
    #     virus_week_day=1,
    #     action=0,
    #     weight=1,
    #     channel=CHANNEL_PC,
    #     category=CATEGORY_BASECONFIG[0],
    #     uid=f'{CATEGORY_BASECONFIG[1]}-5'
    # ),
    # # 按月定时查毒
    # Strategy(
    #     name='按月定时查毒',
    #     description="<span>在每月的{virus_month_day}日，开启{action}扫描定时扫描任务</span>",
    #     virus_month_day=1,
    #     action=0,
    #     weight=1,
    #     channel=CHANNEL_PC,
    #     category=CATEGORY_BASECONFIG[0],
    #     uid=f'{CATEGORY_BASECONFIG[1]}-6'
    # ),
    # Android客户端持续检测设置
    Strategy(
        name='Android客户端持续检测设置',
        description='移动Android终端安全检测每间隔{trigger_period}{type_value}',
        trigger_period=60,
        type_value=0,
        channel=CHANNEL_APP,
        weight=1,
        category=CATEGORY_BASECONFIG[0],
        uid=f'{CATEGORY_BASECONFIG[1]}-7'
    ),
    # Windows客户端持续检测设置
    Strategy(
        name='Windows客户端持续检测设置',
        description='Windows终端安全检测每间隔{trigger_period}{type_value}',
        trigger_period=60,
        type_value=0,
        channel=CHANNEL_PC,
        weight=1,
        category=CATEGORY_BASECONFIG[0],
        uid=f'{CATEGORY_BASECONFIG[1]}-8'
    ),
    # Linux客户端持续检测设置
    Strategy(
        name='Linux客户端持续检测设置',
        description='Linux终端安全检测每间隔{trigger_period}{type_value}',
        trigger_period=60,
        type_value=0,
        channel=CHANNEL_LINUX,
        weight=1,
        category=CATEGORY_BASECONFIG[0],
        uid=f'{CATEGORY_BASECONFIG[1]}-9'
    ),
    # Android端图形验证码启用
    Strategy(
        name='图形验证码启用',
        description='同用户连续登录失败{trigger_times}次出现图形验证码。',
        trigger_times=1,
        type_value=0,
        channel=CHANNEL_APP,
        weight=1,
        action=5,
        category=CATEGORY_BASECONFIG[0],
        uid=f'{CATEGORY_BASECONFIG[1]}-10'
    ),
    # Windows端图形验证码启用
    Strategy(
        name='图形验证码启用',
        description='同用户连续登录失败{trigger_times}次出现图形验证码。',
        trigger_times=1,
        type_value=0,
        channel=CHANNEL_PC,
        weight=1,
        action=5,
        category=CATEGORY_BASECONFIG[0],
        uid=f'{CATEGORY_BASECONFIG[1]}-11'
    ),
    # Web端图形验证码启用
    Strategy(
        name='图形验证码启用',
        description='同用户连续登录失败{trigger_times}次出现图形验证码。',
        trigger_times=1,
        type_value=0,
        channel=CHANNEL_WEB,
        weight=1,
        action=5,
        category=CATEGORY_BASECONFIG[0],
        uid=f'{CATEGORY_BASECONFIG[1]}-12'
    ),
    # Linux端图形验证码启用
    Strategy(
        name='图形验证码启用',
        description='同用户连续登录失败{trigger_times}次出现图形验证码。',
        trigger_times=1,
        type_value=0,
        channel=CHANNEL_LINUX,
        weight=1,
        action=5,
        category=CATEGORY_BASECONFIG[0],
        uid=f'{CATEGORY_BASECONFIG[1]}-13'
    ),
    # Android二次认证启用
    Strategy(
        name='二次认证启用',
        description='二次认证可提升用户身份安全可信度，配置首次认证后需短信验证码认证。',
        channel=CHANNEL_APP,
        type_value=0,
        weight=1,
        action=3,
        category=CATEGORY_BASECONFIG[0],
        uid=f'{CATEGORY_BASECONFIG[1]}-14'
    ),
    # Windows端二次认证启用
    Strategy(
        name='二次认证启用',
        description='二次认证可提升用户身份安全可信度，配置首次认证后需短信验证码认证。',
        channel=CHANNEL_PC,
        type_value=0,
        weight=1,
        action=3,
        category=CATEGORY_BASECONFIG[0],
        uid=f'{CATEGORY_BASECONFIG[1]}-15'
    ),
    # Web端二次认证启用
    Strategy(
        name='二次认证启用',
        description='二次认证可提升用户身份安全可信度，配置首次认证后需短信验证码认证。',
        channel=CHANNEL_WEB,
        type_value=0,
        weight=1,
        action=3,
        category=CATEGORY_BASECONFIG[0],
        uid=f'{CATEGORY_BASECONFIG[1]}-16'
    ),
    # Linux端二次认证启用
    Strategy(
        name='二次认证启用',
        description='二次认证可提升用户身份安全可信度，配置首次认证后需短信验证码认证。',
        channel=CHANNEL_LINUX,
        type_value=0,
        weight=1,
        action=3,
        category=CATEGORY_BASECONFIG[0],
        uid=f'{CATEGORY_BASECONFIG[1]}-17'
    ),

    # 终端威胁（新增）
    # 扫描检出恶意程序和文档
    Strategy(
        name='扫描检出恶意程序和文档',
        description='扫描检出PC终端有恶意程序和文档，提示告知终端，并让用户做出是否删除程序和文档',
        level=LEVEL_HIGH,
        channel=CHANNEL_PC,
        weight=7,
        category=CATEGORY_TERMINAL[0],
        uid=f'{CATEGORY_TERMINAL[1]}-8'
    ),
    # 扫描检出其他类型恶意文件
    Strategy(
        name='扫描检出其他类型恶意文件',
        description='扫描检出PC终端有其他类型恶意文件，提示告知终端，并让用户做出是否删除程序和文档',
        level=LEVEL_HIGH,
        channel=CHANNEL_PC,
        weight=7,
        category=CATEGORY_TERMINAL[0],
        uid=f'{CATEGORY_TERMINAL[1]}-9'
    ),
    # 持续恶意代码检测
    Strategy(
        name='持续恶意代码检测',
        description='登录后如扫描检出终端有恶意代码威胁，提示用户关闭应用并退出登录',
        level=LEVEL_HIGH,
        channel=CHANNEL_LINUX,
        weight=7,
        action=6,
        category=CATEGORY_TERMINAL[0],
        uid=f'{CATEGORY_TERMINAL[1]}-10'
    ),
    # 持续入侵检测
    Strategy(
        name='持续入侵检测',
        description='登录后如扫描检出终端有<span style="color:red">高危</span>入侵威胁，提示用户关闭应用并退出登录；'
                    '如<span style="color:red">中低危</span>则提示用户。',
        level=LEVEL_HIGH,
        channel=CHANNEL_LINUX,
        weight=7,
        action=6,
        category=CATEGORY_TERMINAL[0],
        uid=f'{CATEGORY_TERMINAL[1]}-11'
    ),
    # 持续漏洞检测
    Strategy(
        name='持续漏洞检测',
        description='登录后如扫描检出终端有<span style="color:red">严重、高危</span>漏洞威胁，提示用户关闭应用并退出登录；'
                    '如<span style="color:red">中低危</span>则提示用户。',
        level=LEVEL_HIGH,
        channel=CHANNEL_LINUX,
        weight=7,
        action=6,
        category=CATEGORY_TERMINAL[0],
        uid=f'{CATEGORY_TERMINAL[1]}-12'
    ),

    # 恶意代码检测
    Strategy(
        name='恶意代码检测',
        description='登录前如扫描检出终端有恶意代码威胁，不允许用户登录。如策略关闭则允许用户登录。',
        level=LEVEL_HIGH,
        channel=CHANNEL_LINUX,
        weight=7,
        action=6,
        category=CATEGORY_TERMINAL[0],
        uid=f'{CATEGORY_TERMINAL[1]}-15'
    ),
    # 入侵检测
    Strategy(
        name='入侵检测',
        description='登录前如扫描检出终端有<span style="color:red">高危</span>入侵威胁，不允许用户登录。如策略关闭则允许用户登录。',
        level=LEVEL_HIGH,
        channel=CHANNEL_LINUX,
        weight=7,
        action=6,
        category=CATEGORY_TERMINAL[0],
        uid=f'{CATEGORY_TERMINAL[1]}-16'
    ),
    # 漏洞检测
    Strategy(
        name='漏洞检测',
        description='登录前如扫描检出终端有<span style="color:red">严重、高危</span>漏洞威胁，不允许用户登录，如中低危威胁则允许登录。如策略关闭则允许用户登录。',
        level=LEVEL_HIGH,
        channel=CHANNEL_LINUX,
        weight=7,
        action=6,
        category=CATEGORY_TERMINAL[0],
        uid=f'{CATEGORY_TERMINAL[1]}-17'
    ),
    # # 定时检测周期
    # Strategy(
    #     name='定时检测周期',
    #     description='开启每间隔{num_value}{type_value}一次的终端扫描检测。',
    #     num_value=60,
    #     type_value=0,
    #     channel=CHANNEL_LINUX,
    #     category=CATEGORY_TERMINAL[0],
    #     uid=f'{CATEGORY_TERMINAL[1]}-13'
    # ),

    # 实时防护
    # 文件防护
    Strategy(
        name='文件防护',
        description='<span>开启新增文件防护，防护范围{file_protect}，通过{action}方式处理</span>',
        file_protect=0,
        action=0,
        weight=1,
        channel=CHANNEL_PC,
        category=CATEGORY_REALTIMEPROTECT[0],
        uid=f'{CATEGORY_REALTIMEPROTECT[1]}-1'
    ),
    # 注册表防护
    Strategy(
        name='注册表防护',
        description='<span>开启注册表防护，通过{action}方式处理</span>',
        action=0,
        weight=1,
        channel=CHANNEL_PC,
        category=CATEGORY_REALTIMEPROTECT[0],
        uid=f'{CATEGORY_REALTIMEPROTECT[1]}-2'
    ),
    # MBR防护
    Strategy(
        name='MBR防护',
        description='<span>开启MBR防护，通过{action}方式处理</span>',
        action=0,
        weight=1,
        channel=CHANNEL_PC,
        category=CATEGORY_REALTIMEPROTECT[0],
        uid=f'{CATEGORY_REALTIMEPROTECT[1]}-3'
    ),
    # FTP下载防护
    Strategy(
        name='FTP下载防护',
        description='<span>开启FTP下载防护，通过{action}方式处理</span>',
        action=0,
        weight=1,
        channel=CHANNEL_PC,
        category=CATEGORY_REALTIMEPROTECT[0],
        uid=f'{CATEGORY_REALTIMEPROTECT[1]}-4'
    ),
    # 共享文件防护
    Strategy(
        name='共享文件防护',
        description='<span>开启共享文件防护，通过{action}方式处理</span>',
        action=0,
        weight=1,
        channel=CHANNEL_PC,
        category=CATEGORY_REALTIMEPROTECT[0],
        uid=f'{CATEGORY_REALTIMEPROTECT[1]}-5'
    ),
    # 程序启动防护
    Strategy(
        name='程序启动防护',
        description='<span>开启程序启动防护，通过{action}方式处理</span>',
        action=0,
        weight=1,
        channel=CHANNEL_PC,
        category=CATEGORY_REALTIMEPROTECT[0],
        uid=f'{CATEGORY_REALTIMEPROTECT[1]}-6'
    ),
    # Powershell防护
    Strategy(
        name='Powershell防护',
        description='<span>开启Powershell防护，通过{action}方式处理</span>',
        action=0,
        weight=1,
        channel=CHANNEL_PC,
        category=CATEGORY_REALTIMEPROTECT[0],
        uid=f'{CATEGORY_REALTIMEPROTECT[1]}-7'
    ),
    # 加载防护
    Strategy(
        name='加载防护',
        description='<span>开启加载防护，通过{action}方式处理</span>',
        action=0,
        weight=1,
        channel=CHANNEL_PC,
        category=CATEGORY_REALTIMEPROTECT[0],
        uid=f'{CATEGORY_REALTIMEPROTECT[1]}-8'
    ),
    # 存储设备防护
    Strategy(
        name='存储设备防护',
        description='<span>开启存储设备防护，通过{action}方式处理</span>',
        action=0,
        weight=1,
        channel=CHANNEL_PC,
        category=CATEGORY_REALTIMEPROTECT[0],
        uid=f'{CATEGORY_REALTIMEPROTECT[1]}-9'
    ),

    # 外设管控
    Strategy(
        name='USB设备管控',
        description='<span>插入USB设备时{action}</span>',
        action=0,
        weight=1,
        channel=CHANNEL_PC,
        category=CATEGORY_PERIPHERAL[0],
        uid=f'{CATEGORY_PERIPHERAL[1]}-1'
    ),
    # 移动硬盘管控
    Strategy(
        name='移动硬盘管控',
        description='<span>接入移动硬盘设备时{action}</span>',
        action=0,
        weight=1,
        channel=CHANNEL_PC,
        category=CATEGORY_PERIPHERAL[0],
        uid=f'{CATEGORY_PERIPHERAL[1]}-2'
    ),
    # 打印机管控
    Strategy(
        name='打印机管控',
        description='<span>打印机设置{action}</span>',
        action=0,
        weight=1,
        channel=CHANNEL_PC,
        category=CATEGORY_PERIPHERAL[0],
        uid=f'{CATEGORY_PERIPHERAL[1]}-3'
    ),
    # 便携设备管控
    Strategy(
        name='便携设备管控',
        description='<span>便携设备设置{action}</span>',
        action=0,
        weight=1,
        channel=CHANNEL_PC,
        category=CATEGORY_PERIPHERAL[0],
        uid=f'{CATEGORY_PERIPHERAL[1]}-4'
    ),
    # 网卡管控
    Strategy(
        name='网卡管控',
        description='<span>外置网卡设置{action}</span>',
        action=0,
        weight=1,
        channel=CHANNEL_PC,
        category=CATEGORY_PERIPHERAL[0],
        uid=f'{CATEGORY_PERIPHERAL[1]}-5'
    ),

    # 安全审计
    # 资产档案变更审计（PC端）
    Strategy(
        name='资产档案变更审计（PC端）',
        description='<span>开启{action}资产变更审计 ，资产新增、修改和删除时会上报审计日志</span>',
        action=0,
        weight=1,
        channel=CHANNEL_PC,
        category=CATEGORY_HOSTAUDIT[0],
        uid=f'{CATEGORY_HOSTAUDIT[1]}-1'
    ),
    # 资产档案变更审计（移动端）
    Strategy(
        name='资产档案变更审计（移动端）',
        description='<span>开启{action}资产变更审计 ，资产新增、修改和删除时会上报审计日志</span>',
        action=0,
        weight=1,
        channel=CHANNEL_APP,
        category=CATEGORY_HOSTAUDIT[0],
        uid=f'{CATEGORY_HOSTAUDIT[1]}-2'
    ),
    # 应用访问日志审计
    Strategy(
        name='应用访问日志审计',
        description='开启网关应用访问日志审计功能，详细记录操作时间、账号、源IP、访问应用名称、路径、状态等日志信息',
        weight=1,
        channel=CHANNEL_PC,
        category=CATEGORY_HOSTAUDIT[0],
        uid=f'{CATEGORY_HOSTAUDIT[1]}-3'
    ),
    # 用户登录日志审计
    Strategy(
        name='用户登录日志审计',
        description='开启用户登录访问日志审计功能，详细记录操作时间、账号、源IP、访问应用名称、路径、状态等日志信息',
        weight=1,
        channel=CHANNEL_PC,
        category=CATEGORY_HOSTAUDIT[0],
        uid=f'{CATEGORY_HOSTAUDIT[1]}-4'
    ),
    # 安全日志审计
    Strategy(
        name='安全日志审计',
        description='开启安全日志审计功能，详细记录非法请求地址、非法请求用户名、非法请求IP地址、非法请求时间等信息',
        weight=1,
        channel=CHANNEL_PC,
        category=CATEGORY_HOSTAUDIT[0],
        uid=f'{CATEGORY_HOSTAUDIT[1]}-5'
    ),
]

credit_global_list = [
    CreditGlobalAction(
        level=0,
        sen_mark=1,
        status=1,
        enabled=True,
        score_lower=400,
        score_upper=500,
        config_type=1

    ),
    CreditGlobalAction(
        level=0,
        sen_mark=1,
        status=1,
        enabled=True,
        score_lower=400,
        score_upper=500,
        config_type=2

    ),
    CreditGlobalAction(
        level=0,
        sen_mark=2,
        status=1,
        enabled=True,
        score_lower=400,
        score_upper=500,
        config_type=1

    ),
    CreditGlobalAction(
        level=0,
        sen_mark=2,
        status=1,
        enabled=True,
        score_lower=400,
        score_upper=500,
        config_type=2

    ),
    CreditGlobalAction(
        level=0,
        sen_mark=3,
        status=1,
        enabled=True,
        score_lower=400,
        score_upper=500,
        config_type=1

    ),
    CreditGlobalAction(
        level=0,
        sen_mark=3,
        status=1,
        enabled=True,
        score_lower=400,
        score_upper=500,
        config_type=2

    ),
    CreditGlobalAction(
        level=1,
        sen_mark=1,
        status=1,
        enabled=True,
        score_lower=200,
        score_upper=400,
        config_type=1

    ),
    CreditGlobalAction(
        level=1,
        sen_mark=1,
        status=1,
        enabled=True,
        score_lower=200,
        score_upper=400,
        config_type=2

    ),
    CreditGlobalAction(
        level=1,
        sen_mark=2,
        status=1,
        enabled=True,
        score_lower=200,
        score_upper=400,
        config_type=1

    ),
    CreditGlobalAction(
        level=1,
        sen_mark=2,
        status=1,
        enabled=True,
        score_lower=200,
        score_upper=400,
        config_type=2

    ),
    CreditGlobalAction(
        level=1,
        sen_mark=3,
        status=1,
        enabled=True,
        score_lower=200,
        score_upper=400,
        config_type=1

    ),
    CreditGlobalAction(
        level=1,
        sen_mark=3,
        status=1,
        enabled=True,
        score_lower=200,
        score_upper=400,
        config_type=2

    ),
    CreditGlobalAction(
        level=2,
        sen_mark=1,
        status=1,
        enabled=True,
        score_lower=100,
        score_upper=200,
        config_type=1

    ),
    CreditGlobalAction(
        level=2,
        sen_mark=1,
        status=0,
        enabled=True,
        score_lower=100,
        score_upper=200,
        config_type=2

    ),
    CreditGlobalAction(
        level=2,
        sen_mark=2,
        status=1,
        enabled=True,
        score_lower=100,
        score_upper=200,
        config_type=1

    ),
    CreditGlobalAction(
        level=2,
        sen_mark=2,
        status=0,
        enabled=True,
        score_lower=100,
        score_upper=200,
        config_type=2

    ),
    CreditGlobalAction(
        level=2,
        sen_mark=3,
        status=0,
        enabled=True,
        score_lower=100,
        score_upper=200,
        config_type=1

    ),
    CreditGlobalAction(
        level=2,
        sen_mark=3,
        status=0,
        enabled=True,
        score_lower=100,
        score_upper=200,
        config_type=2

    ),
    CreditGlobalAction(
        level=3,
        sen_mark=1,
        status=1,
        enabled=True,
        score_lower=0,
        score_upper=100,
        config_type=1

    ),
    CreditGlobalAction(
        level=3,
        sen_mark=1,
        status=0,
        enabled=True,
        score_lower=0,
        score_upper=100,
        config_type=2

    ),
    CreditGlobalAction(
        level=3,
        sen_mark=2,
        status=1,
        enabled=True,
        score_lower=0,
        score_upper=100,
        config_type=1

    ),
    CreditGlobalAction(
        level=3,
        sen_mark=2,
        status=0,
        enabled=True,
        score_lower=0,
        score_upper=100,
        config_type=2

    ),
    CreditGlobalAction(
        level=3,
        sen_mark=3,
        status=0,
        enabled=True,
        score_lower=0,
        score_upper=100,
        config_type=1

    ),
    CreditGlobalAction(
        level=3,
        sen_mark=3,
        status=0,
        enabled=True,
        score_lower=0,
        score_upper=100,
        config_type=2

    )
]

# 全局威胁策略处置表 初始化修改
global_strategy_list = [
    # StrategyGlobalAction(
    #     level=1,
    #     action=1,
    #     status=1,
    #     enabled=True,
    #     action_period=60,
    # ),
    # StrategyGlobalAction(
    #     level=1,
    #     action=2,
    #     status=0,
    #     enabled=True,
    #     action_period=60,
    # ),
    # StrategyGlobalAction(
    #     level=1,
    #     action=3,
    #     status=0,
    #     enabled=True,
    #     action_period=60,
    # ),
    # StrategyGlobalAction(
    #     level=1,
    #     action=4,
    #     status=0,
    #     enabled=True,
    #     action_period=60,
    # ),
    # StrategyGlobalAction(
    #     level=2,
    #     action=1,
    #     status=0,
    #     enabled=True,
    #     action_period=60,
    # ),
    # StrategyGlobalAction(
    #     level=2,
    #     action=2,
    #     status=1,
    #     enabled=True,
    #     action_period=60,
    # ),
    # StrategyGlobalAction(
    #     level=2,
    #     action=3,
    #     status=0,
    #     enabled=True,
    #     action_period=60,
    # ),
    # StrategyGlobalAction(
    #     level=2,
    #     action=4,
    #     status=0,
    #     enabled=True,
    #     action_period=60,
    # ),
    # StrategyGlobalAction(
    #     level=3,
    #     action=1,
    #     status=0,
    #     enabled=True,
    #     action_period=60,
    # ),
    # StrategyGlobalAction(
    #     level=3,
    #     action=2,
    #     status=0,
    #     enabled=True,
    #     action_period=60,
    # ),
    # StrategyGlobalAction(
    #     level=3,
    #     action=3,
    #     status=1,
    #     enabled=True,
    #     action_period=60,
    # ),
    # StrategyGlobalAction(
    #     level=3,
    #     action=4,
    #     status=0,
    #     enabled=True,
    #     action_period=60,
    # )
]

# 全局信誉配置表初始化
safety_credit_list = [
    SafetyCreditEvaluation(
        module=1,
        weight=80,
        unit="单次认证失效",
        uid=["STG/AUTH-2", "STG/AUTH-23", "STG/AUTH-24", "STG/AUTH-34"],
        score=3
        ),
    SafetyCreditEvaluation(
        module=1,
        weight=80,
        unit="闲时登出",
        uid=["STG/AUTH-3", "STG/AUTH-25", "STG/AUTH-26", "STG/AUTH-35"],
        score=3
        ),
    SafetyCreditEvaluation(
        module=1,
        weight=80,
        unit="异常时间登录",
        uid=["STG/AUTH-5", "STG/AUTH-27", "STG/AUTH-28", "STG/AUTH-36"],
        score=5
    ),
    # SafetyCreditEvaluation(
    #     module=1,
    #     weight=80,
    #     unit="短信验证失败冻结",
    #     uid=["STG/AUTH-10", "STG/AUTH-11", "STG/AUTH-12"],
    #     score=7
    # ),
    SafetyCreditEvaluation(
        module=1,
        weight=80,
        unit="认证失败冻结",
        uid=["STG/AUTH-13", "STG/AUTH-14", "STG/AUTH-15", "STG/AUTH-33"],
        score=7
    ),
    SafetyCreditEvaluation(
        module=1,
        weight=80,
        unit="二次认证冻结",
        uid=["STG/AUTH-16", "STG/AUTH-17", "STG/AUTH-18", "STG/AUTH-32"],
        score=5
    ),
    SafetyCreditEvaluation(
        module=2,
        weight=80,
        unit="新设备登录预警",
        uid=["STG/DEVICE-7", "STG/DEVICE-8", "STG/DEVICE-13"],
        score=3
    ),
    SafetyCreditEvaluation(
        module=2,
        weight=80,
        unit="异地登录二次认证",
        uid=["STG/DEVICE-9", "STG/DEVICE-10", "STG/DEVICE-14"],
        score=5
    ),
    SafetyCreditEvaluation(
        module=2,
        weight=80,
        unit="单设备登录",
        uid=["STG/DEVICE-1", "STG/DEVICE-2", "STG/DEVICE-11"],
        score=3
    ),
    SafetyCreditEvaluation(
        module=2,
        weight=80,
        unit="设备登录异常二次认证",
        uid=["STG/DEVICE-3", "STG/DEVICE-4", "STG/DEVICE-12"],
        score=5
    ),
    # SafetyCreditEvaluation(
    #     module=2,
    #     weight=80,
    #     unit="用户登录异常二次认证",
    #     uid=["STG/DEVICE-5", "STG/DEVICE-6"],
    #     score=5
    # ),
    SafetyCreditEvaluation(
        module=3,
        weight=80,
        unit="安全基线检测",
        uid=["STG/ENV-16"],
        score=5
    ),
    # SafetyCreditEvaluation(
    #     module=3,
    #     weight=80,
    #     unit="禁止运行录屏软件",
    #     uid=["STG/ENV-9"],
    #     score=5
    # ),
    # SafetyCreditEvaluation(
    #     module=3,
    #     weight=80,
    #     unit="禁止运行远控软件",
    #     uid=["STG/ENV-11"],
    #     score=7
    # ),
    # SafetyCreditEvaluation(
    #     module=3,
    #     weight=80,
    #     unit="杀毒软件需调起运行",
    #     uid=["STG/ENV-13"],
    #     score=7
    # ),
    # SafetyCreditEvaluation(
    #     module=3,
    #     weight=80,
    #     unit="防火墙需调起运行",
    #     uid=["STG/ENV-15"],
    #     score=7
    #     ),
    # SafetyCreditEvaluation(
    #     module=3,
    #     weight=80,
    #     unit="禁止运行虚拟机软件",
    #     uid=["STG/ENV-7"],
    #     score=3
    # ),
    # SafetyCreditEvaluation(
    #     module=3,
    #     weight=80,
    #     unit="设备需运行在安全域（异常设备登录）",
    #     uid=["STG/ENV-6"],
    #     score=3
    # ),
    # SafetyCreditEvaluation(
    #     module=4,
    #     weight=80,
    #     unit="检出敏感APK处置",
    #     uid=["STG/TERM-4"],
    #     score=5
    # ),
    SafetyCreditEvaluation(
        module=4,
        weight=80,
        unit="持续入侵检测",
        uid=["STG/TERM-11"],
        score=7
    ),
    SafetyCreditEvaluation(
        module=4,
        weight=80,
        unit="入侵检测",
        uid=["STG/TERM-16"],
        score=7
    ),
    SafetyCreditEvaluation(
        module=4,
        weight=80,
        unit="持续漏洞检测",
        uid=["STG/TERM-12"],
        score=7
    ),
    SafetyCreditEvaluation(
        module=4,
        weight=80,
        unit="漏洞检测",
        uid=["STG/TERM-17"],
        score=7
    ),
    # SafetyCreditEvaluation(
    #     module=4,
    #     weight=80,
    #     unit="定时检测周期",
    #     uid=["STG/TERM-13"],
    #     score=7
    # ),
    SafetyCreditEvaluation(
        module=4,
        weight=80,
        unit="持续恶意代码检测",
        uid=["STG/TERM-10"],
        score=7
    ),
    SafetyCreditEvaluation(
        module=4,
        weight=80,
        unit="恶意代码检测",
        uid=["STG/TERM-15"],
        score=7
    ),
    # SafetyCreditEvaluation(
    #     module=4,
    #     weight=80,
    #     unit="检出恶意APK处置",
    #     uid=["STG/TERM-2"],
    #     score=7
    # ),
    # SafetyCreditEvaluation(
    #     module=4,
    #     weight=80,
    #     unit="检出风险APK处置",
    #     uid=["STG/TERM-3"],
    #     score=5
    # ),
    # SafetyCreditEvaluation(
    #     module=4,
    #     weight=80,
    #     unit="扫描检出恶意程序和文档",
    #     uid=["STG/TERM-8"],
    #     score=7
    # ),
    # SafetyCreditEvaluation(
    #     module=4,
    #     weight=80,
    #     unit="扫描检出其他类型恶意文件",
    #     uid=["STG/TERM-9"],
    #     score=7
    # ),
    SafetyCreditEvaluation(
        module=5,
        weight=80,
        unit="资源请求频次过高",
        uid=["STG/RES-1", "STG/RES-5", "STG/RES-6", "STG/RES-7"],
        score=7
    ),
    SafetyCreditEvaluation(
        module=5,
        weight=80,
        unit="资源请求越权",
        uid=["STG/RES-8", "STG/RES-9", "STG/RES-10", "STG/RES-2"],
        score=5
        ),
    SafetyCreditEvaluation(
        module=5,
        weight=80,
        unit="资源请求总量过高",
        uid=["STG/RES-11", "STG/RES-12", "STG/RES-13", "STG/RES-3"],
        score=7
    ),
    # SafetyCreditEvaluation(
    #     module=5,
    #     weight=80,
    #     unit="当日资源请求异常",
    #     uid=["STG/RES-14", "STG/RES-15", "STG/RES-16", "STG/RES-4"],
    #     score=7
    # )



]



def strategy_init_data(apps, schema_editor):
    """策略数据初始化"""
    # if not Strategy.objects.exists():
    #     Strategy.objects.bulk_create(strategy_list)
    pass